<?php
require_once('inc.config.php');

# Which path to load by default?
$directory = '.';
if(!empty($_SESSION['current_directory']) && is_dir($_SESSION['current_directory']))
{
	$directory = $_SESSION['current_directory'];
}

# Preferred default home
$home_directory = directory_name_encrypted(isset($home_directory)?$home_directory:dirname(__FILE__));

/**
* Read the file contents for the editor
*/
$contents = '';
#print_r($_GET); die($_GET['file']);
#if(isset($_GET['file']) && is_file($_GET['file']))
if(!empty($_GET['file']) && is_file($_GET['file']))
{
	#  && filesize($_GET['file'])<=20000
	$contents = htmlentities(file_get_contents($_GET['file']));
}
else
{
	$_GET['file']='/tmp/null.txt';
}
#die($contents);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Files Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="editor.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="wrapper">
	<div class="banding">
		<div class="header">
			<h1>PHP File Editor</h1>
			<p>Edit texts files online, replace your FTP uploads</p>
			<p align="right"><a href="help.php">Help</a> | <a href="about.php">About</a> | <a href="contatct.php">Contact</a></p>
		</div>
	</div>

	<div class="change">
		<form id="change-directory" name="change-directory" method="post" action="change-directory.php">
			<input type="text" name="directory" value="<?php echo $directory; ?>" />
			<input type="submit" name="change" id="change" value="Change" />
			<a href="change-directory.php?home=true&amp;directory=<?php echo $home_directory; ?>">home</a>
		</form>
		<div class="breadcrumb"><?php echo breadcrumb($directory); ?></div>
	</div>
	
	<div class="editor-panel">
		<div class="list">
			<h2>List of files</h2>
			<div class="files-list">
<?php
$html = list_files($directory);
if(!is_array($html)) $html = array();
#print_r($html);
echo implode("<br />", $html);
?>
			</div>
		</div>
		<div class="editor">
			<h2 class="title">Edit the contents <?php echo last_modification($_GET['file']); ?></h2>
			<form id="editor-form" name="editor-form" method="post" action="save.php?edit=now">
				<p>
					<textarea name="contents" id="contents" rows="20" cols="72"><?php echo $contents; ?></textarea>
				</p>
				<p>
					<input type="hidden" name="file" value="<?php echo base64_encode($_GET['file']); ?>" />
					<input type="submit" name="button2" id="button2" value="Save" />
					<strong><?php echo $_GET['file']; ?></strong>
				</p>
			</form>
		</div>
	</div>
	<div style="clear:both"></div>
	<div class="footer">&copy; <a href="http://code.google.com/p/php-file-editor/">PHP File Editor</a>, <a href="http://www.sanjaal.com/">Sanjaal Corps</a>, 2011 | No warranties of any kind.</div>
</div>
</body>
</html>